package com.usian.behavior.service.impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.behavior.mapper.BehaviorEntryMapper;
import com.usian.behavior.mapper.FollowBehaviorMapper;
import com.usian.behavior.service.FollowBehaviorService;
import com.usian.model.base.BaseServiceImpl;
import com.usian.model.behavior.pojos.ApBehaviorEntry;
import com.usian.model.behavior.pojos.ApFollowBehavior;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;
@Service
public class FollowBehaviorServiceImpl extends BaseServiceImpl<FollowBehaviorMapper, ApFollowBehavior> implements FollowBehaviorService {
   @Autowired
   private BehaviorEntryMapper entryMapper;

    @Override
    public Boolean followBehaviorSave(Map<String, Object> param) {
        if (param == null)return false;
        Integer userId = Integer.parseInt(param.get("userId").toString());
        Long articleId = Long.valueOf(param.get("articleId").toString());
        Integer followId = Integer.valueOf(param.get("followId").toString());
        if (userId == null || articleId == null || followId == null)return false;
        ApBehaviorEntry entry = entryMapper.selectOne(Wrappers.<ApBehaviorEntry>lambdaQuery().eq(ApBehaviorEntry::getEntryId, userId));
        ApFollowBehavior followBehavior = new ApFollowBehavior();
        followBehavior.setEntryId(entry.getId());
        followBehavior.setArticleId(articleId);
        followBehavior.setFollowId(followId);
        followBehavior.setCreatedTime(new Date());
        return save(followBehavior);
    }
}
